$(function() {
    var grid = $('#grid')._datagrid({
		checkOnSelect : false,
		selectOnCheck : false,
		url : "order/list.html", 
		onBeforeLoad : function(param) {
			if (!$('#queryForm').form('validate')) {
				return false;
			}
			var queryParams = $('#queryForm')._formToJson();
			for (i in queryParams) {
				param[i] = queryParams[i];
			}
		}
	});
    $('#queryButton').click(function(){
        var params = $('#queryForm')._formToJson();
        $(grid).datagrid('load',params);
    });
});
var formatter = {
	transfer_amount : function(value, rowData, rowIndex) {
    	return (rowData.amount-rowData.brokerage).toFixed(2);
	},
	/*dealsms : function(value, rowData, rowIndex) {
		return rowData.deal+"/"+rowData.alls;
	},
	transms : function(value, rowData, rowIndex) {
		return rowData.transfer+"/"+rowData.alls;
	},*/
	cbState : function(value, rowData, rowIndex){
      switch(value) {
      case 0:
      	if(rowData.refundStatus==4){
      		return "<font color='#CD950C'>转账关闭</font>";
      	}else{
      		return "<font color='#CD950C'>处理成功</font>";
      	}
      case 1:
        return "<font color='#EE0000'>待处理</font>";
      case 2:
        return "<font color='#EE0000'>被拒绝</font>";
      case 3:
        return "<font color='#CD00CD'>处理中</font>";
      case 4:
      return "<font color='#CD950C'>处理成功</font>";
      case 5:
        return "<font color='#EE0000'>处理失败</font>";
      }
        return "--";
    },
    refundStatus : function(value, rowData, rowIndex){
      switch(value) {
      case 0:
        return "<font color='#000000'>未申请</font>";
      case 1:
        return "<font color='#CD00CD'>退款中</font>";
      case 2:
        return "<font color='#CD00CD'>退款通过</font>";
      case 3:
      return "<font color='#EE0000'>退款拒绝</font>";
      case 4:
        return "<font color='#CD950C'>退款完成</font>";
      }
        return "--";
    },
    opt : function(value, rowData, rowIndex){
    	var html="";
    	if(rowData.cbState==4){//转账成功后才有转账明细
    		html+='<a class="spacing a-blue" onclick="detail('+rowIndex+');" href="javascript:void(0);">转账明细</a>';  
    	};
    	if(rowData.state==1){ //短信日志  支付成功
    		html+='<a class="spacing a-blue" onclick="smsdetail('+rowIndex+');" href="javascript:void(0);">短信日志</a>';
    	}
    	return html;
    }
};
//转账明细
function detail(rowIndex) {
	var data = $('#grid').datagrid('getRows')[rowIndex];
	var downurl='/orderDownloadPdf.html?billId='+data.billId;
	document.location.href = downurl;
}

//短信日志
function smsdetail(rowIndex) {
    var data = $('#grid').datagrid('getRows')[rowIndex];
    document.location.href = "/menus/pushsms.html?orderNo=" + data.order_num;
}


/**导出*/
$(function() {
	$('#excelExport').click(function(){
		var startDate = $('#startDate').datebox('getValue'); 
		var endDate = $("#endDate").datebox('getValue');
		var order_num = $("#order_num").val();
		var trade_no = $("#trade_no").val();
	   	var channel_name = $("#channel_name").val();
	   	var alipay_name = $("#alipay_name").val();
	   	var shop_name =$("#shop_name").val();
	   	var q_state =$("#q_state").val();
	   document.location.href = "/orderExport.html?startDate=" + startDate+"&endDate="+endDate+"&order_num="+order_num+"&trade_no="+trade_no+"&channel_name="+channel_name+"&alipay_name="+alipay_name+"&shop_name="+shop_name+"&q_state="+q_state;
	});
});